#!/bin/bash
#
# Vary diffuse scattering
#
# Call with 
#
# gsas_vary_diffuse_scattering <histogram> <term> <Flag for amplitude> <flag for radius> <flag for Uiso>
#
# 
#

# echo the call so we can see what's going on
echo "$0 $1 $2 $3 $4 $5 $6"

# Check syntax
if [ "$1" = "" ]; then
	echo "$0 called without a histogram for the diffuse scattering!"
	read -p "This is a problem, you should exit here with Ctrl-c and fix your script..."
	exit 0
fi

if [ "$2" = "" ]; then
	echo "$0 called without a term for the diffuse scattering!"
	read -p "This is a problem, you should exit here with Ctrl-c and fix your script..."
	exit 0
fi

if [ "$3" = "" ]; then
	echo "$0 called without flag for amplitude for diffusce scattering of term $1!"
	read -p "This is a problem, you should exit here with Ctrl-c and fix your script..."
	exit 0
fi

if [ "$4" = "" ]; then
	echo "$0 called without flag for radius for diffusce scattering of term $1!"
	read -p "This is a problem, you should exit here with Ctrl-c and fix your script..."
	exit 0
fi

if [ "$5" = "" ]; then
	echo "$0 called without flag for Uiso for diffusce scattering of term $1!"
	read -p "This is a problem, you should exit here with Ctrl-c and fix your script..."
	exit 0
fi

if [ "$6" = "" ]; then
	echo "$0 called without damping flag, assuming no damping!"
fi


# Add the atom
echo "k l o d" > temp.txt
echo "h $1" >> temp.txt
echo "v" >> temp.txt
echo "$2 $3 $4 $5" >> temp.txt
if [ "$6" = "" ]; then
  echo "Leaving damping untouched"
else
  echo "Setting damping value to $6."
  echo "d $6" >> temp.txt
fi
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt
echo "x" >> temp.txt

expedt `cat GSAS_EXP` < temp.txt > out.txt

echo "Varied for histogram $1 the diffuse scattering term $2, set to $3$4$5 with damping $6.\newline" >> temp.tex



